package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.Customer;
import com.atguigu.jxc.service.CustomerService;
import org.apache.shiro.crypto.hash.Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/customer")
public class CustomerController {
    @Autowired
    private CustomerService customerService;

    /**
     * 客户列表分页
     * @return
     */
    @PostMapping("/list")
    public Map<String,Object> getPage(Integer page, Integer rows, String  customerName){
        List<Customer> list =  customerService.getPage(page,rows,customerName);
        HashMap<String, Object> map = new HashMap<>();
        map.put("total",list.size());
        map.put("rows",list);
        return map;
    }

    /**
     * 更新或插入客户信息
     * @param customer
     * @return
     */
    @PostMapping("save")
    public ServiceVO update(Customer customer){
        customerService.update(customer);
        return new ServiceVO(100,"请求成功");
    }


    /**
     * 批量删除客户信息
     * @param ids
     * @return
     */
    @PostMapping("delete")
    public ServiceVO delete(String  ids){
        customerService.delete(ids);
        return new ServiceVO(100,"请求成功");
    }


    @PostMapping("getComboboxList")
    public List<Customer> getComboboxList(String q){
        return customerService.selectByName(q);
    }


}
